package com.education.wisdom.controller.management;


import com.education.common.utils.ApiReturnObject;
import com.education.wisdom.pojo.Rules;
import com.education.wisdom.service.RulesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;


@RestController
@RequestMapping("/manage/rules")
public class RulesController {

    @Autowired
    private RulesService rulesService;

    @GetMapping("/getRuleList")
    public ApiReturnObject getRuleList() {
        return new ApiReturnObject("200", "查询成功", rulesService.selectRulesList(null));
    }

    @PostMapping("/update")
    public ApiReturnObject update(@RequestBody Rules rules) {
        if (100 < Integer.parseInt(rules.getProportion().toString()) || 0 > Integer.parseInt(rules.getProportion().toString())){
            return new ApiReturnObject("201","比例最高为100或低于0","比例最高为100或低于0");
        }
        rulesService.updateRules(rules);
        return new ApiReturnObject("200", "修改成功", "修改成功");
    }
}
